<template>
  <crec-config-provider :locale="locale">
    <div :id="id" :class="id">
      <template v-if="!isMicro" >
        <router-view v-if="isRouterAlive" />
      </template>
      <BasicLayout v-else/>
    </div>
  </crec-config-provider>
</template>

<script>
import { tools } from 'crec-common'
import config from '@/config/defaultSettings'
import { i18nRender } from '@/locales'
import BasicLayout from '@/layouts/BasicLayout'
export default {
  components: { BasicLayout },
  data () {
    return {
      id: process.env.VUE_APP_NAME,
      isRouterAlive: true
    }
  },
  provide () {
    return {
      reload: this.reload
    }
  },
  computed: {
    locale () {
      // 只是为了切换语言时，更新标题
      const { title } = this.$route.meta
      title && tools.setDocumentTitle(`${i18nRender(title)} - ${config.title}`)

      return this.$i18n.getLocaleMessage(this.$store.getters.lang).antLocale
    },
    isMicro () {
      return window.__POWERED_BY_QIANKUN__
    }
  },
  mounted () {
    if (this.isMicro) {
      // 增加state监听，当mt数据发生变化的时候，我们修改name，体现在页面上
      this.$onGlobalStateChange((state, prev) => {
        this.$store.dispatch('global/initGlobalState', state)
      })
    }
  },
  methods: {
    fn () {
      console.log('aaaa')

      console.log('aaaaa')
    },
    reload () {
      this.isRouterAlive = false
      this.$nextTick(() => {
        this.isRouterAlive = true
      })
    }
  }
}
</script>
